import java.util.Collections;
import java.util.PriorityQueue;

public class towork2 {
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();//默认小根堆
        PriorityQueue<Integer> daQueue=new PriorityQueue<>(Collections.reverseOrder());//使用Collection接口的reversOrder方法实现降序
        int []arr= {1,3,5,7,2,4,6,8};
        int k=4;
        for (int i=0;i<k;i++){
            daQueue.offer(arr[i]);
        }
        for (int i=k;i<arr.length;i++){
            daQueue.offer(arr[i]);
            daQueue.poll();
        }
        System.out.println(daQueue.toString());
    }
}
